package net.tv90.bfmccore.battlepass;

import net.tv90.bfmccore.constant.RewardConstant;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class BattlepassCommand implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (label.equalsIgnoreCase("bps")) {
            if(sender.isOp()) {
                if (args[0].equalsIgnoreCase("save")) {
                    Battlepass.storeBattlepassData();
                }
                if (args[0].equalsIgnoreCase("debug")){
                    System.out.println("=============================================");
                    System.out.println(Battlepass.playerBattlepassData);
                    System.out.println("=============================================");
                    System.out.println(Battlepass.playerDailyPoint);
                    System.out.println("=============================================");
                }
                if(args[0].equalsIgnoreCase("magnification")){
                    RewardConstant.POINT_MAGNIFICATION = Double.parseDouble(args[1]);
                    sender.sendMessage("点数倍率已设置为" + args[1]);
                }
                // /bps giveitem <玩家> <等级> <权限> 获取通行证某等级的物品
                if (args[0].equalsIgnoreCase("giveitem")) {
                    Battlepass.giveRewardPermission(Bukkit.getPlayer(args[1]), Integer.parseInt(args[2]), args[3]);
                }
                // /bps giveitems <玩家> <等级> <权限，英文逗号分隔> 获取通行证某等级的物品
                if (args[0].equalsIgnoreCase("giveitems")) {
                    Battlepass.giveRewardPermissions(Bukkit.getPlayer(args[1]), Integer.parseInt(args[2]), args[3].split(","));
                }
                // /bps giverank <玩家> <等级> <点数> 获取通行证某等级的军衔
                if (args[0].equalsIgnoreCase("giverank")) {
                    Battlepass.giveRewardRank(Bukkit.getPlayer(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3]));
                }
                // /bps givemoney <玩家> <等级> <点数> 获取通行证某等级的游戏币
                if (args[0].equalsIgnoreCase("givemoney")) {
                    Battlepass.giveRewardMoney(Bukkit.getPlayer(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3]));
                }
                // /bps givebattlepack <玩家> <等级> <战斗包等级> 获取通行证某等级的战斗包
                if (args[0].equalsIgnoreCase("givebattlepack")) {
                    Battlepass.giveRewardBattlepack(Bukkit.getPlayer(args[1]), Integer.parseInt(args[2]), args[3]);
                }
                // /bps add <玩家> <级别> 给玩家通行证点数
                if (args[0].equalsIgnoreCase("add")) {
                    Battlepass.enableDailyPointLimit = false;
                    Player p = Bukkit.getPlayer(args[1]);
                    if(p != null) {
                        int level = Integer.parseInt(args[2]);
                        if (level >= Battlepass.MAX_LEVEL) {
                            sender.sendMessage("请检查级别");
                            return false;
                        }
                        for (int i = 0; i < level; i++) {
                            Battlepass.addBattlepassPoint(p, Battlepass.POINT_TO_UPGRADE);
                        }
                        Battlepass.enableDailyPointLimit = true;
                    } else {
                        sender.sendMessage("玩家不在线");
                        return false;
                    }
                }
            }
            if (sender instanceof Player && args[0].equalsIgnoreCase("buy")){
                Battlepass.buyBattlepass((Player) sender);
            }
            if (sender instanceof Player && args[0].equalsIgnoreCase("info")){
                Battlepass.queryBattlepass((Player) sender);
            }
            return true;
        }
        return true;
    }
}
